<?php


namespace plugin\admin\app\logic\style;


use plugin\admin\app\exception\AdminException;
use plugin\admin\app\logic\BaseLogic;
use plugin\admin\app\model\style\OverseaStyle;
use support\Request;
use support\Response;
use plugin\admin\app\common\Auth;

class OverseaStyleLogic extends BaseLogic
{

    public function __construct()
    {
        $this->model = new OverseaStyle;
    }

    public static function getInstance()
    {
        return new self();
    }


    public function select(Request $request): Response
    {
        $field = $request->input('field');
        if($field==false){
            $request->inputSet('field','sort');
            $request->inputSet('order','desc');
        }

        $request->inputSet('isdel','0');
        return parent::select($request);
    }

    public function insert(Request $request): Response
    {
        return parent::insert($request);
    }


    public function update(Request $request): Response
    {
        return parent::update($request);
    }

    public function delete(Request $request): Response
    {
        return parent::isDelete($request);
    }

    public function copy(Request $request): Response
    {
        $first = $this->model->find($request->input('id'));
        if($first==false){
            throw new IndexException(4020,'模板不存在');
        }
        $insert = $first->toArray();
        unset($insert['id'],$insert['created_at'],$insert['updated_at']);
        $insert['name'] = $insert['name'].'-复制';
        $insert['status'] = '0';
        $planid = $this->model->insertGetId($insert);

        return $this->json(0);
    }
}